package com.xl.sst.controller;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.xl.sst.biz.DesiredClassBiz;
import com.xl.sst.vo.DesiredClass;
import com.xl.sst.vo.Page;



/*
 * 需求类别处理层
 * yue
 */
@Controller
@RequestMapping("/view")
public class DesiredClassController {
	@Resource
	private DesiredClassBiz desiredClassBiz;
	public DesiredClassBiz getDesiredClassBiz() {
		return desiredClassBiz;
	}
	public void setDesiredClassBiz(DesiredClassBiz desiredClassBiz) {
		this.desiredClassBiz = desiredClassBiz;
	}
	/*
	 * 添加需求类别
	 * 测试 
	 * http://localhost:8080/SST/view/desclassadd.do?caseId=0&className=dfg&creatUser=1&category=1
	 * 
	 */
	@RequestMapping("/desclassadd.do")
	public @ResponseBody Map<String,Object> add(DesiredClass d){
		Map<String,Object> m=new HashMap<String, Object>();
		if(desiredClassBiz.add(d)){
			m.put("desclassadd", "添加成功！");
		}else{
			m.put("desclassadd", "添加失败！");
		}
		return m;			
	}
	/*
	 * 修改需求类别
	 * 测试
	 * http://localhost:8080/SST4/view/desclassupdate.do?caseId=0&className=trtr&id=18
	 */
	@RequestMapping("/desclassupdate.do")
	public @ResponseBody Map<String,Object> update(DesiredClass d){
		Map<String,Object> m=new HashMap<String, Object>();
		if(desiredClassBiz.update(d)){
			m.put("desclassupdate", "修改成功！");
		}else{
			m.put("desclassupdate", "修改失败！");
		}
		return m;			
	}
	/*
	 * 删除需求类别
	 * 测试
	 * http://localhost:8080/SST4/view/desclassdelete.do?id=19
	 */
	@RequestMapping("/desclassdelete.do")
	public @ResponseBody Map<String,Object> delete(DesiredClass d){
		Map<String,Object> m=new HashMap<String, Object>();
		int i=desiredClassBiz.delete(d);
		if(i>=1){
			m.put("desclassdelete", "成功删除"+i+"条需求！");
		}else{
			m.put("desclassdelete", "删除失败！");
		}
		return m;			
	}
	/*
	 * 根据caseID为0查询需求大类别  
	 * 测试
	 * http://localhost:8080/SST4/view/desclassselectBig.do?category=0
	 */
	@RequestMapping("/desclassselectBig.do")
	public @ResponseBody List<DesiredClass> selectBig(DesiredClass d){		
		return desiredClassBiz.selectBig(d);			
	}
	/*
	 * 根据caseID不为0查询需求小类别  
	 * 测试
	 * http://localhost:8080/SST4/view/desclassselectSmall.do?index=1
	 */
	@RequestMapping("/desclassselectSmall.do")
	public @ResponseBody List<DesiredClass> selectSmall(Page d){
		System.out.println(desiredClassBiz.selectSmall(d).size());
		return desiredClassBiz.selectSmall(d);			
	}
	
}
